load("//tools/lint:lint.bzl", "add_lint_tests")
load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_googletest",
    "drake_cc_library",
    "drake_cc_package_library",
)

package(default_visibility = ["//visibility:public"])

drake_cc_package_library(
    name = "trajectories",
    visibility = ["//visibility:public"],
    deps = [
        ":bezier_curve",
        ":bspline_trajectory",
        ":composite_trajectory",
        ":derivative_trajectory",
        ":discrete_time_trajectory",
        ":function_handle_trajectory",
        ":path_parameterized_trajectory",
        ":piecewise_constant_curvature_trajectory",
        ":piecewise_polynomial",
        ":piecewise_pose",
        ":piecewise_quaternion",
        ":piecewise_trajectory",
        ":stacked_trajectory",
        ":trajectory",
        ":wrapped_trajectory",
    ],
)

drake_cc_library(
    name = "bezier_curve",
    srcs = [
        "bezier_curve.cc",
    ],
    hdrs = [
        "bezier_curve.h",
    ],
    deps = [
        ":trajectory",
        "//common:drake_bool",
        "//common/symbolic:polynomial",
        "//math:binomial_coefficient",
    ],
)

drake_cc_library(
    name = "bspline_trajectory",
    srcs = [
        "bspline_trajectory.cc",
    ],
    hdrs = [
        "bspline_trajectory.h",
    ],
    deps = [
        ":trajectory",
        "//common:name_value",
        "//math:bspline_basis",
    ],
)

drake_cc_library(
    name = "composite_trajectory",
    srcs = [
        "composite_trajectory.cc",
    ],
    hdrs = [
        "composite_trajectory.h",
    ],
    deps = [
        ":path_parameterized_trajectory",
        ":piecewise_polynomial",
        ":piecewise_trajectory",
    ],
)

drake_cc_library(
    name = "derivative_trajectory",
    srcs = ["derivative_trajectory.cc"],
    hdrs = ["derivative_trajectory.h"],
    deps = [
        ":trajectory",
        "//common:default_scalars",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "discrete_time_trajectory",
    srcs = ["discrete_time_trajectory.cc"],
    hdrs = ["discrete_time_trajectory.h"],
    deps = [
        ":piecewise_polynomial",
        ":trajectory",
        "//common:default_scalars",
        "//common:essential",
        "//math:matrix_util",
    ],
)

drake_cc_library(
    name = "function_handle_trajectory",
    srcs = ["function_handle_trajectory.cc"],
    hdrs = ["function_handle_trajectory.h"],
    deps = [
        ":derivative_trajectory",
        ":trajectory",
        "//common:default_scalars",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "path_parameterized_trajectory",
    srcs = ["path_parameterized_trajectory.cc"],
    hdrs = ["path_parameterized_trajectory.h"],
    deps = [
        ":derivative_trajectory",
        ":trajectory",
        "//common:default_scalars",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "piecewise_polynomial",
    srcs = [
        "exponential_plus_piecewise_polynomial.cc",
        "piecewise_polynomial.cc",
    ],
    hdrs = [
        "exponential_plus_piecewise_polynomial.h",
        "piecewise_polynomial.h",
    ],
    compile_once_per_scalar = True,
    deps = [
        ":piecewise_trajectory",
        "//common:default_scalars",
        "//common:essential",
        "//common:name_value",
        "//common:polynomial",
        "//math:binomial_coefficient",
        "//math:matrix_util",
        "@fmt",
    ],
)

drake_cc_library(
    name = "piecewise_constant_curvature_trajectory",
    srcs = ["piecewise_constant_curvature_trajectory.cc"],
    hdrs = ["piecewise_constant_curvature_trajectory.h"],
    deps = [
        ":piecewise_trajectory",
        "//common:essential",
        "//common:pointer_cast",
        "//math:geometric_transform",
        "//math:wrap_to",
        "//multibody/math:spatial_algebra",
        "//systems/framework:system_scalar_converter",
    ],
)

drake_cc_library(
    name = "piecewise_pose",
    srcs = ["piecewise_pose.cc"],
    hdrs = ["piecewise_pose.h"],
    deps = [
        ":piecewise_polynomial",
        ":piecewise_quaternion",
        "//common:essential",
        "//common:pointer_cast",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "piecewise_quaternion",
    srcs = ["piecewise_quaternion.cc"],
    hdrs = ["piecewise_quaternion.h"],
    deps = [
        ":piecewise_polynomial",
        ":piecewise_trajectory",
        "//common:essential",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "piecewise_trajectory",
    srcs = ["piecewise_trajectory.cc"],
    hdrs = ["piecewise_trajectory.h"],
    deps = [
        ":trajectory",
        "//common:default_scalars",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "stacked_trajectory",
    srcs = ["stacked_trajectory.cc"],
    hdrs = ["stacked_trajectory.h"],
    deps = [
        ":trajectory",
        "//common:reset_after_move",
    ],
)

drake_cc_library(
    name = "trajectory",
    srcs = ["trajectory.cc"],
    hdrs = ["trajectory.h"],
    deps = [
        "//common:default_scalars",
        "//common:essential",
        "//common:unused",
    ],
)

drake_cc_library(
    name = "wrapped_trajectory",
    srcs = ["wrapped_trajectory.cc"],
    hdrs = ["wrapped_trajectory.h"],
    deps = [
        ":trajectory",
    ],
)

# === test/ ===

drake_cc_googletest(
    name = "bezier_curve_test",
    deps = [
        ":bezier_curve",
        "//common/symbolic:polynomial",
        "//common/test_utilities",
        "//geometry/optimization:convex_set",
        "//solvers:mathematical_program",
    ],
)

drake_cc_googletest(
    name = "bspline_trajectory_test",
    deps = [
        ":bspline_trajectory",
        "//common:find_resource",
        "//common/proto:call_python",
        "//common/test_utilities",
        "//common/yaml",
        "//math:compute_numerical_gradient",
        "//math:gradient",
    ],
)

drake_cc_googletest(
    name = "composite_trajectory_test",
    deps = [
        ":bezier_curve",
        ":composite_trajectory",
        "//common/test_utilities",
    ],
)

drake_cc_googletest(
    name = "derivative_trajectory_test",
    deps = [
        ":derivative_trajectory",
        ":discrete_time_trajectory",
        ":piecewise_polynomial",
        ":piecewise_quaternion",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "discrete_time_trajectory_test",
    deps = [
        ":discrete_time_trajectory",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "function_handle_trajectory_test",
    deps = [
        ":function_handle_trajectory",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "exponential_plus_piecewise_polynomial_test",
    deps = [
        ":piecewise_polynomial",
        ":random_piecewise_polynomial",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "path_parameterized_trajectory_test",
    deps = [
        ":path_parameterized_trajectory",
        ":piecewise_polynomial",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "piecewise_constant_curvature_trajectory_test",
    deps = [
        ":piecewise_constant_curvature_trajectory",
        ":piecewise_quaternion",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "piecewise_polynomial_generation_test",
    # Test timeout increased to not timeout when run with Valgrind.
    timeout = "moderate",
    srcs = ["test/piecewise_polynomial_generation_test.cc"],
    deps = [
        ":piecewise_polynomial",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_no_throw",
    ],
)

drake_cc_googletest(
    name = "piecewise_polynomial_test",
    deps = [
        ":piecewise_polynomial",
        ":random_piecewise_polynomial",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//common/yaml",
        "//math:gradient",
    ],
)

drake_cc_googletest(
    name = "piecewise_pose_test",
    deps = [
        ":piecewise_pose",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "piecewise_quaternion_test",
    deps = [
        ":piecewise_quaternion",
        "//common/test_utilities:eigen_matrix_compare",
        "//math:wrap_to",
    ],
)

drake_cc_googletest(
    name = "piecewise_trajectory_test",
    deps = [
        ":piecewise_trajectory",
    ],
)

drake_cc_library(
    name = "random_piecewise_polynomial",
    testonly = 1,
    hdrs = ["test/random_piecewise_polynomial.h"],
    deps = [
        "//common/test_utilities:random_polynomial_matrix",
    ],
)

drake_cc_googletest(
    name = "stacked_trajectory_test",
    deps = [
        ":discrete_time_trajectory",
        ":piecewise_polynomial",
        ":stacked_trajectory",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "trajectory_test",
    deps = [
        ":trajectory",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "wrapped_trajectory_test",
    deps = [
        ":function_handle_trajectory",
        ":wrapped_trajectory",
        "//common/test_utilities:expect_throws_message",
    ],
)

add_lint_tests()
